// Decompiled by Jad v1.5.8f. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 

package jagex;

import java.io.PrintStream;

// Referenced classes of package jagex:
//            b

public class DataFileDecrypter {

	public static int unpackData(byte arg0[], int arg1, byte arg2[], int arg3,
			int arg4) {
		DataFileVariables dataFileVariables = new DataFileVariables();
		dataFileVariables.t = arg2;
		dataFileVariables.u = arg4;
		dataFileVariables.y = arg0;
		dataFileVariables.z = 0;
		dataFileVariables.v = arg3;
		dataFileVariables.ab = arg1;
		dataFileVariables.hb = 0;
		dataFileVariables.gb = 0;
		dataFileVariables.w = 0;
		dataFileVariables.x = 0;
		dataFileVariables.bb = 0;
		dataFileVariables.cb = 0;
		dataFileVariables.jb = 0;
		vj(dataFileVariables);
		arg1 -= dataFileVariables.ab;
		return arg1;
	}

	private static void wj(DataFileVariables arg0) {
		byte byte4 = arg0.db;
		int i = arg0.eb;
		int j = arg0.ob;
		int k = arg0.mb;
		int ai[] = DataFileVariables.rb;
		int l = arg0.lb;
		byte abyte0[] = arg0.y;
		int i1 = arg0.z;
		int j1 = arg0.ab;
		int k1 = j1;
		int l1 = arg0.fc + 1;
		label0: do {
			if (i > 0) {
				do {
					if (j1 == 0) {
						break label0;
					}
					if (i == 1) {
						break;
					}
					abyte0[i1] = byte4;
					i--;
					i1++;
					j1--;
				} while (true);
				if (j1 == 0) {
					i = 1;
					break;
				}
				abyte0[i1] = byte4;
				i1++;
				j1--;
			}
			boolean flag = true;
			while (flag) {
				flag = false;
				if (j == l1) {
					i = 0;
					break label0;
				}
				byte4 = (byte) k;
				l = ai[l];
				byte byte0 = (byte) (l & 0xff);
				l >>= 8;
				j++;
				if (byte0 != k) {
					k = byte0;
					if (j1 == 0) {
						i = 1;
					} else {
						abyte0[i1] = byte4;
						i1++;
						j1--;
						flag = true;
						continue;
					}
					break label0;
				}
				if (j != l1) {
					continue;
				}
				if (j1 == 0) {
					i = 1;
					break label0;
				}
				abyte0[i1] = byte4;
				i1++;
				j1--;
				flag = true;
			}
			i = 2;
			l = ai[l];
			byte byte1 = (byte) (l & 0xff);
			l >>= 8;
			if (++j != l1) {
				if (byte1 != k) {
					k = byte1;
				} else {
					i = 3;
					l = ai[l];
					byte byte2 = (byte) (l & 0xff);
					l >>= 8;
					if (++j != l1) {
						if (byte2 != k) {
							k = byte2;
						} else {
							l = ai[l];
							byte byte3 = (byte) (l & 0xff);
							l >>= 8;
							j++;
							i = (byte3 & 0xff) + 4;
							l = ai[l];
							k = (byte) (l & 0xff);
							l >>= 8;
							j++;
						}
					}
				}
			}
		} while (true);
		int i2 = arg0.bb;
		arg0.bb += k1 - j1;
		if (arg0.bb < i2) {
			arg0.cb++;
		}
		arg0.db = byte4;
		arg0.eb = i;
		arg0.ob = j;
		arg0.mb = k;
		DataFileVariables.rb = ai;
		arg0.lb = l;
		arg0.y = abyte0;
		arg0.z = i1;
		arg0.ab = j1;
	}

	private static void vj(DataFileVariables arg0) {
		boolean flag = false;
		boolean flag1 = false;
		boolean flag2 = false;
		boolean flag3 = false;
		boolean flag4 = false;
		boolean flag5 = false;
		boolean flag6 = false;
		boolean flag7 = false;
		boolean flag8 = false;
		boolean flag9 = false;
		boolean flag10 = false;
		boolean flag11 = false;
		boolean flag12 = false;
		boolean flag13 = false;
		boolean flag14 = false;
		boolean flag15 = false;
		boolean flag16 = false;
		boolean flag17 = false;
		boolean flag18 = false;
		int k8 = 0;
		int ai[] = null;
		int ai1[] = null;
		int ai2[] = null;
		arg0.ib = 1;
		if (DataFileVariables.rb == null) {
			DataFileVariables.rb = new int[arg0.ib * 0x186a0];
		}
		boolean flag19 = true;
		while (flag19) {
			byte byte0 = tj(arg0);
			if (byte0 == 23) {
				return;
			}
			byte0 = tj(arg0);
			byte0 = tj(arg0);
			byte0 = tj(arg0);
			byte0 = tj(arg0);
			byte0 = tj(arg0);
			arg0.jb++;
			byte0 = tj(arg0);
			byte0 = tj(arg0);
			byte0 = tj(arg0);
			byte0 = tj(arg0);
			byte0 = yj(arg0);
			if (byte0 != 0) {
				arg0.fb = true;
			} else {
				arg0.fb = false;
			}
			if (arg0.fb) {
				System.out.println("PANIC! RANDOMISED BLOCK!");
			}
			arg0.kb = 0;
			byte0 = tj(arg0);
			arg0.kb = arg0.kb << 8 | byte0 & 0xff;
			byte0 = tj(arg0);
			arg0.kb = arg0.kb << 8 | byte0 & 0xff;
			byte0 = tj(arg0);
			arg0.kb = arg0.kb << 8 | byte0 & 0xff;
			for (int j = 0; j < 16; j++) {
				byte byte1 = yj(arg0);
				if (byte1 == 1) {
					arg0.ub[j] = true;
				} else {
					arg0.ub[j] = false;
				}
			}

			for (int k = 0; k < 256; k++) {
				arg0.tb[k] = false;
			}

			for (int l = 0; l < 16; l++) {
				if (arg0.ub[l]) {
					for (int i3 = 0; i3 < 16; i3++) {
						byte byte2 = yj(arg0);
						if (byte2 == 1) {
							arg0.tb[l * 16 + i3] = true;
						}
					}

				}
			}

			xj(arg0);
			int i4 = arg0.sb + 2;
			int j4 = zj(3, arg0);
			int k4 = zj(15, arg0);
			for (int i1 = 0; i1 < k4; i1++) {
				int j3 = 0;
				do {
					byte byte3 = yj(arg0);
					if (byte3 == 0) {
						break;
					}
					j3++;
				} while (true);
				arg0.zb[i1] = (byte) j3;
			}

			byte abyte0[] = new byte[6];
			for (byte byte16 = 0; byte16 < j4; byte16++) {
				abyte0[byte16] = byte16;
			}

			for (int j1 = 0; j1 < k4; j1++) {
				byte byte17 = arg0.zb[j1];
				byte byte15 = abyte0[byte17];
				for (; byte17 > 0; byte17--) {
					abyte0[byte17] = abyte0[byte17 - 1];
				}

				abyte0[0] = byte15;
				arg0.yb[j1] = byte15;
			}

			for (int k3 = 0; k3 < j4; k3++) {
				int l6 = zj(5, arg0);
				for (int k1 = 0; k1 < i4; k1++) {
					do {
						byte byte4 = yj(arg0);
						if (byte4 == 0) {
							break;
						}
						byte4 = yj(arg0);
						if (byte4 == 0) {
							l6++;
						} else {
							l6--;
						}
					} while (true);
					arg0.ac[k3][k1] = (byte) l6;
				}

			}

			for (int l3 = 0; l3 < j4; l3++) {
				byte byte8 = 32;
				int i = 0;
				for (int l1 = 0; l1 < i4; l1++) {
					if (arg0.ac[l3][l1] > i) {
						i = arg0.ac[l3][l1];
					}
					if (arg0.ac[l3][l1] < byte8) {
						byte8 = arg0.ac[l3][l1];
					}
				}

				ak(arg0.bc[l3], arg0.cc[l3], arg0.dc[l3], arg0.ac[l3], byte8,
						i, i4);
				arg0.ec[l3] = byte8;
			}

			int l4 = arg0.sb + 1;
			int l5 = 0x186a0 * arg0.ib;
			int i5 = -1;
			int j5 = 0;
			for (int i2 = 0; i2 <= 255; i2++) {
				arg0.nb[i2] = 0;
			}

			int j9 = 4095;
			for (int l8 = 15; l8 >= 0; l8--) {
				for (int i9 = 15; i9 >= 0; i9--) {
					arg0.wb[j9] = (byte) (l8 * 16 + i9);
					j9--;
				}

				arg0.xb[l8] = j9 + 1;
			}

			int i6 = 0;
			if (j5 == 0) {
				i5++;
				j5 = 50;
				byte byte12 = arg0.yb[i5];
				k8 = arg0.ec[byte12];
				ai = arg0.bc[byte12];
				ai2 = arg0.dc[byte12];
				ai1 = arg0.cc[byte12];
			}
			j5--;
			int i7 = k8;
			int l7;
			byte byte9;
			for (l7 = zj(i7, arg0); l7 > ai[i7]; l7 = l7 << 1 | byte9) {
				i7++;
				byte9 = yj(arg0);
			}

			for (int k5 = ai2[l7 - ai1[i7]]; k5 != l4;) {
				if (k5 == 0 || k5 == 1) {
					int j6 = -1;
					int k6 = 1;
					do {
						if (k5 == 0) {
							j6 += k6;
						} else if (k5 == 1) {
							j6 += 2 * k6;
						}
						k6 *= 2;
						if (j5 == 0) {
							i5++;
							j5 = 50;
							byte byte13 = arg0.yb[i5];
							k8 = arg0.ec[byte13];
							ai = arg0.bc[byte13];
							ai2 = arg0.dc[byte13];
							ai1 = arg0.cc[byte13];
						}
						j5--;
						int j7 = k8;
						int i8;
						byte byte10;
						for (i8 = zj(j7, arg0); i8 > ai[j7]; i8 = i8 << 1
								| byte10) {
							j7++;
							byte10 = yj(arg0);
						}

						k5 = ai2[i8 - ai1[j7]];
					} while (k5 == 0 || k5 == 1);
					j6++;
					byte byte5 = arg0.vb[arg0.wb[arg0.xb[0]] & 0xff];
					arg0.nb[byte5 & 0xff] += j6;
					for (; j6 > 0; j6--) {
						DataFileVariables.rb[i6] = byte5 & 0xff;
						i6++;
					}

				} else {
					int j11 = k5 - 1;
					byte byte6;
					if (j11 < 16) {
						int j10 = arg0.xb[0];
						byte6 = arg0.wb[j10 + j11];
						for (; j11 > 3; j11 -= 4) {
							int k11 = j10 + j11;
							arg0.wb[k11] = arg0.wb[k11 - 1];
							arg0.wb[k11 - 1] = arg0.wb[k11 - 2];
							arg0.wb[k11 - 2] = arg0.wb[k11 - 3];
							arg0.wb[k11 - 3] = arg0.wb[k11 - 4];
						}

						for (; j11 > 0; j11--) {
							arg0.wb[j10 + j11] = arg0.wb[(j10 + j11) - 1];
						}

						arg0.wb[j10] = byte6;
					} else {
						int l10 = j11 / 16;
						int i11 = j11 % 16;
						int k10 = arg0.xb[l10] + i11;
						byte6 = arg0.wb[k10];
						for (; k10 > arg0.xb[l10]; k10--) {
							arg0.wb[k10] = arg0.wb[k10 - 1];
						}

						arg0.xb[l10]++;
						for (; l10 > 0; l10--) {
							arg0.xb[l10]--;
							arg0.wb[arg0.xb[l10]] = arg0.wb[(arg0.xb[l10 - 1] + 16) - 1];
						}

						arg0.xb[0]--;
						arg0.wb[arg0.xb[0]] = byte6;
						if (arg0.xb[0] == 0) {
							int i10 = 4095;
							for (int k9 = 15; k9 >= 0; k9--) {
								for (int l9 = 15; l9 >= 0; l9--) {
									arg0.wb[i10] = arg0.wb[arg0.xb[k9] + l9];
									i10--;
								}

								arg0.xb[k9] = i10 + 1;
							}

						}
					}
					arg0.nb[arg0.vb[byte6 & 0xff] & 0xff]++;
					DataFileVariables.rb[i6] = arg0.vb[byte6 & 0xff] & 0xff;
					i6++;
					if (j5 == 0) {
						i5++;
						j5 = 50;
						byte byte14 = arg0.yb[i5];
						k8 = arg0.ec[byte14];
						ai = arg0.bc[byte14];
						ai2 = arg0.dc[byte14];
						ai1 = arg0.cc[byte14];
					}
					j5--;
					int k7 = k8;
					int j8;
					byte byte11;
					for (j8 = zj(k7, arg0); j8 > ai[k7]; j8 = j8 << 1 | byte11) {
						k7++;
						byte11 = yj(arg0);
					}

					k5 = ai2[j8 - ai1[k7]];
				}
			}

			arg0.eb = 0;
			arg0.db = 0;
			arg0.pb[0] = 0;
			for (int j2 = 1; j2 <= 256; j2++) {
				arg0.pb[j2] = arg0.nb[j2 - 1];
			}

			for (int k2 = 1; k2 <= 256; k2++) {
				arg0.pb[k2] += arg0.pb[k2 - 1];
			}

			for (int l2 = 0; l2 < i6; l2++) {
				byte byte7 = (byte) (DataFileVariables.rb[l2] & 0xff);
				DataFileVariables.rb[arg0.pb[byte7 & 0xff]] |= l2 << 8;
				arg0.pb[byte7 & 0xff]++;
			}

			arg0.lb = DataFileVariables.rb[arg0.kb] >> 8;
			arg0.ob = 0;
			arg0.lb = DataFileVariables.rb[arg0.lb];
			arg0.mb = (byte) (arg0.lb & 0xff);
			arg0.lb >>= 8;
			arg0.ob++;
			arg0.fc = i6;
			wj(arg0);
			if (arg0.ob == arg0.fc + 1 && arg0.eb == 0) {
				flag19 = true;
			} else {
				flag19 = false;
			}
		}
	}

	private static byte tj(DataFileVariables arg0) {
		return (byte) zj(8, arg0);
	}

	private static byte yj(DataFileVariables arg0) {
		return (byte) zj(1, arg0);
	}

	private static int zj(int arg0, DataFileVariables arg1) {
		int i;
		do {
			if (arg1.hb >= arg0) {
				int j = arg1.gb >> arg1.hb - arg0 & (1 << arg0) - 1;
				arg1.hb -= arg0;
				i = j;
				break;
			}
			arg1.gb = arg1.gb << 8 | arg1.t[arg1.u] & 0xff;
			arg1.hb += 8;
			arg1.u++;
			arg1.v--;
			arg1.w++;
			if (arg1.w == 0) {
				arg1.x++;
			}
		} while (true);
		return i;
	}

	private static int bk(int arg0, int arg1[]) {
		int i = 0;
		int j = 256;
		do {
			int k = i + j >> 1;
			if (arg0 >= arg1[k]) {
				i = k;
			} else {
				j = k;
			}
		} while (j - i != 1);
		return i;
	}

	private static void xj(DataFileVariables arg0) {
		arg0.sb = 0;
		for (int i = 0; i < 256; i++) {
			if (arg0.tb[i]) {
				arg0.vb[arg0.sb] = (byte) i;
				arg0.sb++;
			}
		}

	}

	private static void ak(int arg0[], int arg1[], int arg2[], byte arg3[],
			int arg4, int arg5, int arg6) {
		int i = 0;
		for (int j = arg4; j <= arg5; j++) {
			for (int i2 = 0; i2 < arg6; i2++) {
				if (arg3[i2] == j) {
					arg2[i] = i2;
					i++;
				}
			}

		}

		for (int k = 0; k < 23; k++) {
			arg1[k] = 0;
		}

		for (int l = 0; l < arg6; l++) {
			arg1[arg3[l] + 1]++;
		}

		for (int i1 = 1; i1 < 23; i1++) {
			arg1[i1] += arg1[i1 - 1];
		}

		for (int j1 = 0; j1 < 23; j1++) {
			arg0[j1] = 0;
		}

		int j2 = 0;
		for (int k1 = arg4; k1 <= arg5; k1++) {
			j2 += arg1[k1 + 1] - arg1[k1];
			arg0[k1] = j2 - 1;
			j2 <<= 1;
		}

		for (int l1 = arg4 + 1; l1 <= arg5; l1++) {
			arg1[l1] = (arg0[l1 - 1] + 1 << 1) - arg1[l1];
		}

	}

	public DataFileDecrypter() {
	}

	static final int js = 1;
	static final int ks = 2;
	static final int ls = 10;
	static final int ms = 14;
	static final int ns = 0;
	static final int os = 4;
	static final int ps = 4096;
	static final int qs = 16;
	static final int rs = 258;
	static final int ss = 23;
	static final int ts = 0;
	static final int us = 1;
	static final int vs = 6;
	static final int ws = 50;
	static final int xs = 4;
	static final int ys = 18002;
}
